package com.itjason.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itjason.mapper.WxRegionalDialectMapper;
import com.itjason.po.RegionalDataPO;
import com.itjason.service.WxRegionalDialectPageService;
import com.itjason.vo.RegionalDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Author:JasonLong
 * Date:2023/5/11
 * Time:17:51
 * 地区方言业务接口实现类
 */
@Service
public class WxRegionalDialectPageServiceImpl implements WxRegionalDialectPageService {

    @Autowired
    private WxRegionalDialectMapper regionalDialectMapper;

    /**
     * 通过地区标记获取对应地区的数据
     *
     * @param regionFlag
     * @return RegionalDataVO
     */
    @Override
    public List getRegionLanguagePack(String regionFlag) {
        QueryWrapper<RegionalDataPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("nation_area_flag", regionFlag).eq("deleted", 0);
        List<RegionalDataVO> regionalDataVoList = regionalDialectMapper.selectList(queryWrapper).stream().map(m -> {
            RegionalDataVO regionalDataVO = new RegionalDataVO();
            regionalDataVO.setNationAreaVoiceurl(m.getNationAreaVoiceurl());
            regionalDataVO.setNationAreaTranslation(m.getNationAreaTranslation());
            regionalDataVO.setIsplay(m.getIsplay());
            regionalDataVO.setRegionFlag(m.getNationAreaFlag());
            return regionalDataVO;
        }).collect(Collectors.toList());
        return regionalDataVoList;
    }

    @Override
    public List getRegionDataByKeyword(String keyword, String regionFlag) {
        QueryWrapper<RegionalDataPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("nation_area_translation", keyword).like("nation_area_flag", regionFlag).eq("deleted", 0);
        List<RegionalDataVO> regionalDataVoList = regionalDialectMapper.selectList(queryWrapper).stream().map(m -> {
            RegionalDataVO regionalDataVO = new RegionalDataVO();
            regionalDataVO.setNationAreaVoiceurl(m.getNationAreaVoiceurl());
            regionalDataVO.setNationAreaTranslation(m.getNationAreaTranslation());
            regionalDataVO.setIsplay(m.getIsplay());
            regionalDataVO.setRegionFlag(m.getNationAreaFlag());
            return regionalDataVO;
        }).collect(Collectors.toList());
        return regionalDataVoList;
    }

}
